#!/bin/sh
#
# mmm_agent    This shell script takes care of starting and stopping
#              the mmm monitoring daemon.
#
# chkconfig: - 64 36
# description:	MMM Monitor.
# processname: mmmd_mon
# config: /opt/mmm/mmm_mont.conf
# pidfile: /opt/mmm/var/mmmd_mon.pid

# Cluster name (it can be empty for default cases)
CLUSTER=''

# Paths
MMMD_BASE="/opt/mmm"

#-----------------------------------------------------------------------
if [ "$CLUSTER" != "" ]; then
    MMMD_BIN="${MMMD_BASE}/mmmd_mon @$CLUSTER"
    MMMD_PIDFILE="${MMMD_BASE}/var/mmmd-$CLUSTER.pid"
else 
    MMMD_BIN="${MMMD_BASE}/mmmd_mon"
    MMMD_PIDFILE="${MMMD_BASE}/var/mmmd.pid"
fi

echo "Daemon bin: '$MMMD_BIN'"
echo "Daemon pid: '$MMMD_PIDFILE'"

exit 0

#-----------------------------------------------------------------------
# See how we were called.
case "$1" in
  start)
	# Start daemon.
	echo -n "Starting MMM Monitor daemon: "
	$MMMD_AGENT_BIN $CLUSTER
	RETVAL=$?
	echo "Ok"
	;;

  stop)
	# Stop daemon.
	echo -n "Shutting down MMM Monitor daemon: "
	kill `cat $MMMD_AGENT_PIDFILE`
	RETVAL=$?
	echo "Ok"
	;;

  restart|reload)
	$0 stop
	echo -n "Waiting 10 sec before restart...";
	sleep 10
	echo "Ok"
	$0 start
	;;

  *)
	echo "Usage: $0 {start|stop|restart}"
	RETVAL=1
	;;
esac

exit $RETVAL
